package com.fqxl.labour.service.impl;

import com.fqxl.labour.domain.LabourJob;
import com.fqxl.labour.domain.vo.PageVo;
import com.fqxl.labour.mapper.JobMapper;
import com.fqxl.labour.service.JobService;
import com.fqxl.labour.untils.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class JobServiceImpl implements JobService {

    @Autowired
    private JobMapper jobMapper;

    /**
     * 发布招工信息
     * @param labourJob
     * @return
     */
    @Override
    public R addJob(LabourJob labourJob) {
        jobMapper.addJob(labourJob);
        return R.ok("发布成功");
    }

    /**
     * 查询招工信息列表
     * @param pageVo
     * @return
     */
    @Override
    public R selectJob(PageVo pageVo) {

        PageHelper.startPage(pageVo.getPage(),pageVo.getSize());
        List<LabourJob> labourJobs = jobMapper.selectJob();
        PageInfo pageInfo = new PageInfo(labourJobs);

        return R.ok(pageInfo);
    }

    /**
     *根据id查询招工详情
     * @param id
     * @return
     */
    @Override
    public R getJobById(String id) {
        LabourJob jobById = jobMapper.getJobById(id);
        return R.ok(jobById);
    }

    /**
     * 发布求职信息
     * @param labourJob
     * @return
     */
    @Override
    public R addJobs(LabourJob labourJob) {
        jobMapper.addJobs(labourJob);
        return R.ok("发布成功");
    }

    /**
     * 查询发布求职信息
     * @param pageVo
     * @return
     */
    @Override
    public R selectJobs(PageVo pageVo) {

        PageHelper.startPage(pageVo.getPage(), pageVo.getSize());
        List<LabourJob> labourJobs = jobMapper.selectJobs();
        PageInfo pageInfo = new PageInfo(labourJobs);

        return R.ok(pageInfo);
    }

    /**
     * 根据id查询求职详情
     * @param id
     * @return
     */
    @Override
    public R getSelectByIds(String id) {
        LabourJob selectByIds = jobMapper.getSelectByIds(id);
        return R.ok(selectByIds);
    }

    /**
     * 我发布的信息
     * @param pageVo
     * @return
     */
    @Override
    public R selectUserId(PageVo pageVo) {

        PageHelper.startPage(pageVo.getPage(), pageVo.getSize());
        List<LabourJob> labourJobs = jobMapper.selectUserId();
        PageInfo pageInfo = new PageInfo(labourJobs);

        return R.ok(pageInfo);
    }


}
